<template>
  <Menu ref="sideMenu" :active-name="$route.meta.menuId" :open-names="openNames" :theme="menuTheme" width="auto" @on-select="changeMenu">
    <MenuItem name="home">
      <Icon type="ios-home" size="19"></Icon>
      <span class="layout-text">首页</span>
    </MenuItem>
    <template v-for="menu in menuList">
      <MenuItem v-if="menu.list.length < 1" :name="menu.menuId" :key="menu.menuId">
        <Icon :type="menu.icon" size="19" :key="'menuicon' + menu.menuId"></Icon>
        <span class="layout-text" :key="'title' + menu.menuId">{{ itemTitle(menu) }}</span>
      </MenuItem>

      <Submenu v-if="menu.list.length >= 1" :name="menu.name" :key="menu.menuId">
        <template slot="title">
          <Icon :type="menu.icon" size="19"></Icon>
          <span class="layout-text">{{ itemTitle(menu) }}</span>
        </template>
        <template v-for="child in menu.list">
          <MenuItem v-if="child.name !== '订单修改'" :name="child.menuId" :key="'menuitem' + child.menuId">
            <Icon :type="child.icon" size="19" :key="'icon' + child.menuId"></Icon>
            <span class="layout-text" :key="'title' + child.menuId">{{ itemTitle(child) }}</span>
          </MenuItem>
        </template>
      </Submenu>
    </template>
  </Menu>
</template>

<script>
export default {
  name: 'sidebarMenu',
  props: {
    menuList: Array,
    iconSize: Number,
    menuTheme: {
      type: String,
      default: 'dark'
    },
    openNames: {
      type: Array
    }
  },
  methods: {
    changeMenu (active) {
      this.$emit('on-change', active);
    },
    itemTitle (item) {
      return item.name;
    }
  },
  updated () {
    this.$nextTick(() => {
      if (this.$refs.sideMenu) {
        this.$refs.sideMenu.updateOpened();// 手动展开更新的子目录
      }
    });
  }

};
</script>

<style lang="less">
  .ivu-shrinkable-menu{
    height: 100%;
    width: 100%;
  }
</style>
